var common = {
	//随机字符
	randStr:function(length){
		var chars = "abcdefghijkmnpqrstuvwxyzABCDEFGHIJKMNPQRSTUVWXYZ23456789";
		var str = "";
		var charLen = chars.length;
		while(str.length<length){
			var randNum = Math.floor(Math.random()*charLen+1);
			str += chars.substr(randNum,1);
		}
		return str;
	},
	
	//更换验证码
	changeVerify:function(verifyImgID,verifyImgUrl){
		$('#'+verifyImgID).attr('src',verifyImgUrl+'?code='+Math.random());
		return false;
	},
	
	rescript:function(value){
		return value.replace(/[^\w\d]/g,'');
	},
	
	//定时跳转
	gotoUrl:function(url,time){
		if(time < 1){
			window.location.href = url;
			return;
		}
		setTimeout("common.gotoUrl("+"'"+url+"'"+",0)",time*1000);
	},
    
    addMask:function(color,alpha,width,height){
        if(!color)
            color = '#000';
        if(isNaN(alpha))
            alpha = 0.5;
        if(isNaN(width))
        	width = $(document).width();
        if(isNaN(height))
        	height = $(document).height();
        var styles = 'width:'+width+'px; height:'+height+'px; filter: Alpha(opacity='+(alpha*100)+');opacity:'+alpha+'; background:'+color+'; position:absolute; z-index:100';
        var mask = '<div id="commonMask" style="'+styles+'"></div>';
        $('body').prepend(mask);
        return $("#commonMask");
    },
    
    removeMask:function(){
    	var maskObj = $("#commonMask");
    	if(maskObj)
    		maskObj.remove();
    },
    
    loadCssFile:function(cssFile){
        var cssLink = '<link href="'+cssFile+'" rel="stylesheet" type="text/css" />';
        $('head').prepend(cssLink);
    },
    
    removeCssFile:function(cssFile){
        $('link').each(function(){
            if(this.href == cssFile){
                $(this).remove();
                return false;
            }
        });
    }
}


var target=[];
var time_id=[];
function show_date_time_0(){ 
    setTimeout("show_date_time_0()", 1000); 
for (var i=0,j=target.length;i<j;i++){ 
    today=new Date(); 
    timeold=target[i]-today.getTime(); 
    sectimeold=timeold/1000; 
    secondsold=Math.floor(sectimeold); 
    msPerDay=24*60*60*1000; 
    e_daysold=timeold/msPerDay; 
    daysold=Math.floor(e_daysold); 
    e_hrsold=(e_daysold-daysold)*24; 
    hrsold=Math.floor(e_hrsold); 
    e_minsold=(e_hrsold-hrsold)*60; 
    minsold=Math.floor((e_hrsold-hrsold)*60); 
    seconds=Math.floor((e_minsold-minsold)*60); 
    if (daysold<0) { 
        document.getElementById(time_id[i]).innerHTML="逾期,倒计时已经失效"; 
    }  
    else { 
        if (daysold<10) {daysold="0"+daysold} 
       // if (daysold<100) {daysold="0"+daysold} 
        if (hrsold<10) {hrsold="0"+hrsold} 
        if (minsold<10) {minsold="0"+minsold} 
        if (seconds<10) {seconds="0"+seconds} 
        if (daysold<3) { 
            document.getElementById(time_id[i]).innerHTML="<font color=red>"+daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒</font>"; 
        }  
        else { 
            document.getElementById(time_id[i]).innerHTML=daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒"; 
        } 
    } 
} 
}
setTimeout("show_date_time_0()", 100);


// utility function to retrieve an expiration data in proper format;
function getExpDate(days, hours, minutes)
{
    var expDate = new Date();
    if(typeof(days) == "number" && typeof(hours) == "number" && typeof(hours) == "number")
    {
        expDate.setDate(expDate.getDate() + parseInt(days));
        expDate.setHours(expDate.getHours() + parseInt(hours));
        expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
        return expDate.toGMTString();
    }
}

//utility function called by getCookie()
function getCookieVal(offset)
{
    var endstr = document.cookie.indexOf(";", offset);
    if(endstr == -1)
    {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}

// primary function to retrieve cookie by name
function getCookie(name)
{
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while(i < clen)
    {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
        {
            return getCookieVal(j);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if(i == 0) break;
    }
    return;
}

// store cookie value with optional details as needed
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

// remove the cookie by setting ancient expiration date
function deleteCookie(name,path,domain)
{
    if(getCookie(name))
    {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

